# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_pyname=qtpy
_realname=qtpy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.4.3
pkgrel=1
pkgdesc='Provides an abstraction layer on top of the various Qt bindings (PyQt5/6 and PySide2/6). (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/spyder-ide/qtpy/"
msys2_references=(
  'purl: pkg:pypi/qtpy'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: Qt5 Python bindings"
            "${MINGW_PACKAGE_PREFIX}-python-pyqt6: Qt6 Python bindings"
            "${MINGW_PACKAGE_PREFIX}-pyside2: PySide Qt5 Python bindings"
            "${MINGW_PACKAGE_PREFIX}-pyside6: PySide Qt6 Python bindings")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=(!strip)
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz"
        001-restore-qtwebkit-support.patch)
sha256sums=('db744f7832e6d3da90568ba6ccbca3ee2b3b4a890c3d6fbbc63142f6e4cdf5bb'
            'f93c29bbe11addc2ae56b47c8660d9c8b9ef45b125f5f9c6fb8018ea590da909')

prepare() {
  cd "$srcdir"/${_pyname}-${pkgver}
  patch -p1 -i "$srcdir"/001-restore-qtwebkit-support.patch

  cd "$srcdir"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
